public class Solution7 {
    //309. 买卖股票的最佳时机含冷冻期
    public int maxProfit(int[] prices) {
        int n  = prices.length;
        int[] f = new int[n]; //买入
        int[] g = new int[n]; //卖出
        int[] h = new int[n]; //冷冻期
        f[0] = -prices[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(f[i-1],h[i-1]-prices[i]);
            g[i] = Math.max(g[i-1],prices[i]+f[i-1]);
            h[i] = g[i-1];
        }
        return g[n-1];
    }
}
